<?php
/**
 * 3D柱状图2维多项多列
 * 
 * PHP version 5
 *
 * @package   Ecga
 * @author    Farmer.Li <none@none.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   SVN: $Id$
 */
namespace Project\Apps\Ecga\Library\FusionCharts;

use \Project\Apps\Ecga\Library\FusionCharts\ChartXml;
use \Exception;

/**
 * 3D柱状图2维多项多列
 * PHP version 5
 *
 * @package   Ecga
 * @author    Farmer.Li <none@none.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   Release: <0.2>
 */
class MSColumn3DMultiseriate extends ChartXml
{
	protected $tmpData = array();
	
	/**
	 * 设置图表数据
	 * 数据格式:
	 * $data = array(
	 *		'项目名1' => '当前指定系列的值'
	 *		'项目名2' => '当前指定系列的值'
	 * );
	 * 项目名必须是已指定的值
	 *
	 * @param string $servies    系列名. 必须是已指定的系列
	 * @param string $color      颜色
	 * @param array  $data 	     格式化数组
	 * @param int 	 $showValues 未知的属性
	 * 
	 * @return object
	 */
	public function setData($servies, $color = '', $data = array(), $showValues = 0)
	{
		$this->tmpData[$servies] = array(
			'color' => $color ? $color : $this->randColor(),
			'showValues' => $showValues > 0 ? 1 : 0,
			'data' => $data
		);
	}
	
	/**
	 * 格式化数据
	 * 
	 * @return void
	 */
	protected function format()
	{
		$this->data['__child']['categories'] = array(
			'tagName' => 'categories'
		);
		$tmpCate = current($this->tmpData);
		$categories = array_keys($tmpCate['data']);
		foreach ($categories as $category) {
			$this->data['__child']['categories']['__child'][$category] = array(
				'tagName' => 'category',
				'__attr' => array(
					'label' => $category
				)
			);
		}
		foreach ($this->tmpData as $service => $datas) {
			$tmp = array(
				'tagName' => 'dataset',
				'__attr' => array(
					'seriesName' => $service,
					'color' => $datas['color'],
					'showValues' => $datas['showValues'],
				),
			);
			foreach ($categories as $category) {
				$tmp['__child'][] = array(
					'tagName' => 'set',
					'__attr' => array(
						'value' => $datas['data'][$category]
					)
				);
			}
			$this->data['__child'][$service] = $tmp;
		}
	}
}
?>